function routerResponse(option = {}) {
  return async function (ctx, next) {
    ctx.success = function (message, data) {
      ctx.type = option.type || 'json'
      ctx.body = {
        code: option.successCode || 0,
        message: message,
        data: data,
      }
    }

    ctx.warning = function (message) {
      ctx.type = option.type || 'json'
      ctx.body = {
        code: option.warningCode || 1,
        message: message,
      }
    }
    await next()
  }

}

module.exports = routerResponse